#include "linebuffer.h"

LineBuffer::LineBuffer(const std::string &sep) : separator(sep)
{

}

bool LineBuffer::getLine(std::string &line)
{
    std::scoped_lock  locker(bufferMutex);
    std::string::size_type pos = buffer.find(separator);
    if(pos == std::string::npos)
        return false;
    line = buffer.substr(0, pos);
    buffer.erase(0, pos+1);
    return true;
}

bool LineBuffer::pushToBuffer(const std::string &text)
{
    std::scoped_lock locker(bufferMutex);
    buffer += text;
    return true;
}
